
public class ParkingManage {
    public Car[] cars = new Car[100];
    public  static int maxNumber = 100;
    public static int currentNumber = 0;
    public static int id = 0;


    public void enterParking(String lpn){
        if(currentNumber <= maxNumber){
            this.cars[id] = new Car();
            this.cars[id].setLpn(lpn);
            this.cars[id].enter(id);
            currentNumber++;
            id++;
        }else {
            System.out.println("没有车位了!");
        }
    }
    public void outParking(String lpn) {
        int i = 0;
        for (i = 0; i < id; i++) {
            if(this.cars[i].getLpn().equals(lpn) && this.cars[i].parking.getNo() != -1){
                currentNumber--;
                this.cars[i].out();
                this.cars[i].parking.setCost(this.cars[i].calculateCost());
                break;
            }
        }
        if(i == id) System.out.println("该车没有进行入库登记!");
    }
    public int totalCost(){
        int sum = 0;
        for (int i = 0; i < id; i++) {
            sum += this.cars[i].parking.getCost();
        }
        return sum;
    }
    public Boolean hasPosition(){
        if(currentNumber <= maxNumber) return true;
        else return false;
    }
    public Car searchCar(String lpn){
        int f = 0;
        Car car = new Car();
        for (int i = 0; i < id; i++) {
            if(this.cars[i].getLpn().equals(lpn)){
                f = 1;
                car = cars[i];
                break;
            }
        }
        if (f == 0){
            System.out.println("车库中没有该车!");
            return  null;
        }
        else return car;
    }
    public void show(){
        System.out.println("车库一共服务" + id + "辆汽车") ;
        System.out.println("车库还有" + (maxNumber - currentNumber) + "辆车位!");

    }
}
